# coding=utf-8
import math

from lxml import etree;
import re;

def _readHtml(filePath):
    html = '';
    with open(filePath, 'r', encoding= 'utf-8') as f:
        for line in f:
            html = html + line;
    return html;

def getWaterfallCtrPageId(html):
    searchObject  = re.search("""window.__APLUS_ABRATE__\['p4p_id'\] = \"(.*)\"""", html,re.M|re.I);
    if searchObject:
        print("find waterfallCtrPageId:", searchObject.group(1))
        return searchObject.group(1);
    else:
        return '';

def getItems(html):
    htmlTree = etree.HTML(html);
    # path = htmlTree.xpath('//*[@id="root"]/div/div[3]/div[2]/div/div/div/div[1]/div/div[2]/div[1]/h4/a/@href');
    # path = htmlTree.xpath('//div[@class="organic-list app-organic-search__list"]/div')

    path = htmlTree.xpath('//script')


    # path = htmlTree.xpath('//div[@class="offer-list-wrapper"/div]', smart_strings=False)
        # .xpath('//div[@class="app-organic-search__content-main"]');
    # print(path);
    for index in range(len(path)):
        print("========%s========" % index)
        print(etree.tostring(path[index], encoding='utf-8').decode('utf-8'))
    # print(etree.tostring(path[40], encoding='utf-8').decode('utf-8'))
    # print(len(path))


if __name__ == '__main__':
    html =_readHtml("localHtml.html");
    # getItems(html);
    # print(html);
    waterfallCtrPageId = getWaterfallCtrPageId(html);
    print(waterfallCtrPageId)

    # html = '';
    # html = html.join(['abc'])
    # print(html.join(['abc3']));
    # print(html.join(['abc']));
    # print(html)
    # print(1/3);
    # print(bin(-888));

